﻿using Mimas.Core.Current;
using Mimas.Framework.Shared.Data.DataTransferObjects;
using System;
using System.Linq;

namespace Mimas.Framework.Server.DomainObjects.Mapping
{
    public static class LookupListItemLangMapping
    {
        public static LookupListItemLang Map(LookupListItemLangDTO data)
        {
            LookupListItemLang newItem = new LookupListItemLang();

            newItem.Id = data.Id;
            newItem.LanguageId = data.LanguageId;
            newItem.LookupListItemId = data.LookupListItemId;
            newItem.Name = Culture.ToTitleCase(data.Name);

            if (data.Id == 0)
            {
                newItem.CreatedBy = UserInfo.CurrentUser.UserId;
                newItem.CreatedOn = DateTime.Now;
            }
            else
            {
                newItem.ModifiedBy = UserInfo.CurrentUser.UserId;
                newItem.ModifiedOn = DateTime.Now;
            }

            return newItem;
        }

        public static LookupListItemLangDTO Map(LookupListItemLang data)
        {
            LookupListItemLangDTO newItem = new LookupListItemLangDTO();

            newItem.Id = data.Id;
            newItem.LanguageId = data.LanguageId;
            newItem.LookupListItemId = data.LookupListItemId;
            newItem.Name = Culture.ToTitleCase(data.Name);

            return newItem;
        }

        public static LookupListItemLang[] Map(LookupListItemLangDTO[] data)
        {
            if (data == null || !data.Any()) return null;
            return data.Where(x => x != null).Select(x => Map(x)).ToArray();
        }

        public static LookupListItemLangDTO[] Map(LookupListItemLang[] data)
        {
            if (data == null || !data.Any()) return null;
            return data.Where(x => x != null).Select(x => Map(x)).ToArray();
        }
    }
}
